<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Dcat\Admin\Traits\HasUploadedFile;
use OSS\Core\OssException;
use OSS\OssClient;

class UploadfileController extends Controller
{

    use HasUploadedFile, OssUpload;

         /**
          * 上传文件到oss
          *
          * @param Request $request
          * @param string $type
          * @return \Illuminate\Http\JsonResponse
          */
         public function handle(Request $request)
     {
         $disk = $this->disk('oss');

         // 判断是否是删除文件请求
         if ($this->isDeleteRequest()) {
             // 删除文件并响应
             return $this->deleteFileAndResponse($disk);
         }

         // 获取上传的文件
         $file = $this->file();
         dd($file);
         // 获取上传的字段名称
         $column = $this->uploader()->upload_column;
         $object =date('H-i:s') . '.';
         $dir = 'goods/'.date('Y-m-d');
         $newName = $object.$file->getClientOriginalExtension();
         $result = $disk->putFileAs($dir, $file, $newName);
         $path = "{$dir}/$newName";
         //审核图片
         $imageUrl = env('ALIYUN_IS_CNAME').$result;
//         //调用图片审核方法
//         $imageContentReview = ImageContentReview::contentReview($imageUrl);
//         $resultImageContentReview = $imageContentReview['Data']['Results'][0]['SubResults'][0]['Label'];
//         if ($resultImageContentReview == 'normal'){
//             return $result
//                 ? $this->responseUploaded($path, $disk->url($path))
//                 : $this->responseErrorMessage('文件上传失败');
//         }else{
//             return  $this->responseErrorMessage('性感图片/色情图片,请重新上传');
//         }
     }

}
